import os
import time
import unittest
from lib.HTMLTestRunner import HTMLTestRunner


if __name__ == '__main__':
    path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'test_case')
    suite = unittest.defaultTestLoader.discover(path, pattern="test*.py")

    # 生成测试报告verbosity = 2 使报告更详细
    project_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
    report_dir = os.path.join(project_root, 'report')
    # 测试报告地址
    current_time = time.strftime("%Y-%m-%d_%H-%M-%S")
    report_abspath = os.path.join(report_dir, "HTMLReport_{}.html".format(current_time))
    with open(report_abspath, 'wb') as f:
        runner = HTMLTestRunner(stream=f,
                                title='Web UI自动化测试报告',
                                description='测试用例执行情况',
                                verbosity=2
                                )
        runner.run(suite)


